<?php
require_once "inc/MainMenu.php";
$mainMenu = new MainMenu();
require_once "inc/Themes.php";
require_once "inc/Fortune.php";
require_once "inc/TalPage.php";
require_once "inc/TalesPage.php";
require_once "inc/Lorem.php";

$theme = new Themes();

$path = explode('/',substr($_SERVER['REQUEST_URI'],1));
//var_dump($path);
if ($path[0] == 'setTheme') {
	//echo "changing theme";
	$theme->setTheme($path[1]);
	header('Location: /');
	die();
}

require_once '../lib/MicroTal.php';
$head = new MicroTal();
$head->base = 'http://'.$_SERVER['HTTP_HOST'].'/'.$theme->getThemeDir();


$head->setRelativeTemplateDir('templates/');
$head = $head->execute("head.xhtml");
$tal = new MicroTal();

$tal->slogan = "completly diffrent from other micro software";
$tal->siteName ="MicroTAL";
//var_dump($theme->getSelectorData());
$tal->themes = $theme->getSelectorData();
$tal->head = $head;
$tal->links = array(
	'Sidebar Menu' => array(
		'Home' => "/",
		'TemplateInfo' => "/",
		'Style Demo' => '/style.html',
		'Blog' => '/blog.html',
		'More Free Templates' => 'http://www.styleshout.com/',
		'Premium Templates' => 'http://www.4templates.com/?aff=ealigam',
		'' => '',
		'' => '',
		),
	'Links' => array(
		'Alistapart' => 'http://www.alistapart.com',
		'CSS Remix' => 'http://www.cssremix.com',
		'CSS Mania' => 'http://www.cssmania.com/',
		'' => '',
	),
	'(ME)TAL(ES) (Zope Page Templates)' => array(
		'TAL Specification 1.4' => 'http://wiki.zope.org/ZPT/TALSpecification14',
		'TALES Specification 1.3' => 'http://wiki.zope.org/ZPT/TALESSpecification13',
		'Zope Page Templates SimpleTutorial ' => 'http://wiki.zope.org/ZPT/SimpleTutorial',
		
	),
	'PHP resources' => array('Smarty' => 'http://'),
	'TAL resources' => array('TAL/TALES & METAL Reference Guide' => 'http://www.owlfish.com/software/simpleTAL/tal-guide.html',
		'SimpleTal' => 'http://www.owlfish.com/software/simpleTAL/',
		'Zope Page Templates '=>'http://zpt.sourceforge.net/',
),
	'XHTML/CSS resources' => array(),
);
$tal->mainMenu = $mainMenu->getMenu();

$tal->fortune = Fortune::get();
$tal->setRelativeTemplateDir('/');
$tal->lorem = new Lorem();

$request = Request::getInstance();
switch($request->path[0]) {
	case 'tal':
		$page = new TalPage();
		break;
	case 'tales':
		$page = new TalesPage();
		break;
	default:
		$page = new CorePage();
}
$tal->items = $page->getItems();
if (file_exists('pages/'.$request->path[0].'.xhtml')) {
	$tal->page= $tal->execute('pages/'.$request->path[0].'.xhtml');
} else {
	$tal->page= $tal->execute('pages/index.xhtml');
}
echo $tal->execute($theme->getThemeDir().'index.html');